package psd.model.Prolog.Converters;

import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.IPackageBinding;
import org.eclipse.jdt.core.dom.ImportDeclaration;

import psd.model.IConverter;
import psd.model.Prolog.FactGenerationToolbox;
import psd.model.Prolog.PrologConverter;


public class PrologImportDeclarationConverter extends PrologConverter implements
IConverter<ImportDeclaration>{

	public PrologImportDeclarationConverter(FactGenerationToolbox toolbox) {
		super(toolbox);
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean convert(ImportDeclaration node) {
		  String id = idResolver.getID(node);
	        String topLevel = getParentId(node);
	        IBinding binding = node.resolveBinding();
	        if(binding != null && binding.getKind() == 1)
	        {
	            generatePackageFactIfNecessary((IPackageBinding)binding);
	        }
	        String importName = idResolver.getID(binding);
	        String args[] = {
	            id, topLevel, importName, this.getFilePath(node), this.getLineNumber(node)
	        };
	        writer.writeFact("importT", args);
	        if(node.isStatic())
	        {
	            writeModifier(node, "static");
	        }
	        writer.writeFact("slT", new String[] {
	            idResolver.getID(node), Integer.toString(node.getStartPosition()), Integer.toString(node.getLength()), this.getFilePath(node), this.getLineNumber(node)
	        });
	        checkAndGenComments(node, id);
	        //createAnnotationFact(node, idResolver.getID(node));
	        return false;
	}

}
